import network from '../../utils/network.js'; 
var time = require('../../utils/timeUtil.js');
//获取应用实例
const app = getApp()
const baseUrl = 'http://jbc.com';

Page({
 
    /**
     * 页面的初始数据
     */
    data: {
      userInfo:[],
      isHiddenToast: true,
      page: 1,
      rows: 10,
      total: 0,
      hasMoreData: true,
      list: [],
      //当前选中导航的Inx值
      Inx: 0
    },
 
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function () {
      // 页面初始化 options为页面跳转所带来的参数
      var that = this;
      wx.getStorage({//获取本地缓存
        key: "user",
        success: function (res) {
          that.setData({
            userInfo: res.data,
          });
          that.getManager_list('正在加载数据...')
        }
      });  
    },

 //通过审核
  checkPass:function(e){
    var that = this;
    const id = e.currentTarget.dataset.id
    const user_id = that.data.userInfo.id;
    var data = {
      id: id,
      user_id: user_id,
      status:1
    };
    console.log(data);
    const message = "正在审核中";
    that.checkCommit(data,message);
  },
  //通过审核
  checkRefuse: function (e) {
    var that = this;
    const id = e.currentTarget.dataset.id
    const user_id = that.data.userInfo.id;
    var data = {
      id: id,
      user_id: user_id,
      status: 0
    };
    console.log(data);
    const message = "正在审核中";
    that.checkCommit(data, message);
  },


  checkCommit :function(data, message){
    var that = this;
    network.requestLoading(baseUrl+'/System/User/manager_commit', data, message, function (res) {
      if (res.code > 0) {
        wx.showToast({
          title: res.msg,
        });
        that.data.page = 1;
        that.data.list = [];
        that.getManager_list('正在刷新数据')
      } else {
        wx.showToast({
          title: res.msg,
        });
      }
    }, function (res) {
      wx.showToast({
        title: '加载数据失败',
      })

    })
  },

  //获取业务经理申请列表
  getManager_list: function (message) {
    var that = this;
    const shop_id = that.data.userInfo.shop_id;
    var datas = that.data;
    var data = {
      shop_id: shop_id,
      ischeck: 0,
      page: datas.page,
      rows: datas.rows
    };
    network.requestLoading(baseUrl+'/System/User/manager_list', data, message, function (res) {
      var contentlistTem = that.data.list;
      if (res.code > 0) {
        if (contentlistTem.length < res.data.total) 
        {
          for(var i=0;i< res.data.list.length;i++){
            res.data.list[i].addtime = time.formatTimeTwo(res.data.list[i].addtime, 'Y-m-d h:m:s');
          }
          that.setData({
            page: datas.page + 1,
            list: res.data.list,
          });
        } else {
          that.setData({
            hasMoreData: false
          });
        }

      } else {
        wx.showToast({
          title: res.msg,
        })
      }
    }, function (res) {
      wx.showToast({
        title: '加载数据失败',
      })

    })
  },
  /**
 * 页面相关事件处理函数--监听用户下拉动作
 */
  onPullDownRefresh: function () {
    this.data.page = 1;
    this.getManager_list('正在刷新数据')
    console.log("下拉加载更多")
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log("下滑加载更多")
    if (this.data.hasMoreData) {
      this.getManager_list('加载更多数据');
    } else {
      console.log("没有更多的数据")
      wx.showToast({
        title: '没有更多数据',
      })
    }
  },
 
})
